package mylib.archive.y2012.m09.IFMO_Train;

import mylib.dir.FastInputReader;

import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;

public class TaskC {
    public void solve(int testNumber, FastInputReader in, PrintWriter out) {
//        for (int n = 2, it = 0; it < 1; ++n) {
//            if (good(n)) {
//                ++it;
//                out.print("a[" + it + "] = " + n + ";\n");
//            }
//        }
        ArrayList<BigInteger> list = new ArrayList<BigInteger>();
        for (long s = 1; s <= 10000; ++s) {
            BigInteger d = BigInteger.valueOf(s);
            d = d.multiply(d);
            for (int pow = 2; pow <= 100; ++pow, d = d.multiply(BigInteger.valueOf(s))) {
                if (good(d)) {
                    if (d.compareTo(BigInteger.ONE) > 0)
                        list.add(d);
                }
            }
        }

        Collections.sort(list);
        ArrayList<BigInteger> e = new ArrayList<BigInteger>();
        for (int i = 0, j = 0; i < list.size(); i = j) {
            for (j = i; j < list.size() && list.get(i).equals(list.get(j)); ++j) ;
            e.add(list.get(i));
        }
        //out.print(e.size());
        PrintWriter sl = null;
        try {
            sl = new PrintWriter("gen.txt");
        } catch (FileNotFoundException e1) {
            e1.printStackTrace();
        }
        for (int i = 0; i < 200; ++i) {
            sl.print("a[" + i + "] = new BigInteger(\"" + e.get(i) + "\");\n");
        }
        sl.flush();


    }

    private boolean good(BigInteger n) {
        BigInteger s = BigInteger.valueOf(sum(n));
        BigInteger t = s.add(BigInteger.ZERO);
        s = s.multiply(t);
        while (s.compareTo(n) < 0 && !t.equals(BigInteger.ONE)) {
            s = s.multiply(t);
        }
        return s.equals(n);
    }

    private int sum(BigInteger n) {
        return n.equals(BigInteger.ZERO) ? 0 : (int) (sum(n.divide(BigInteger.TEN)) + n.mod(BigInteger.TEN).intValue());
    }
}
